<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<%@ page language="java" 
	import="java.util.*, java.text.SimpleDateFormat, com.bean.library.Term, com.bean.library.Course, com.bean.library.Paper" %>
<jsp:useBean id="term" class = "com.bean.library.Term" scope="session"></jsp:useBean>
<jsp:useBean id="student" class = "com.bean.library.Student" scope="session"></jsp:useBean>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
	<title>Exam</title>
    <link rel="stylesheet" href="../css/exam.css" type="text/css" />
    <link rel="stylesheet" href="../css/common.css" type="text/css" />
    <link rel="stylesheet" href="../css/left_course.css" type="text/css" />
    <script type="text/javascript" src="../scripts/jquery-1.7.2.min.js"></script>
    <script type="text/javascript" src="../scripts/jquery.animate-colors-min.js"></script>
    <script type="text/javascript" src="../scripts/navi_common.js"></script>
    <script type="text/javascript">
        $(function () {
            $("#choose_logo").hover(function () {
                $(this).animate({ backgroundColor: '#30A8F4' }, { speed: 1000, queue: false });
            }, function () {
                $(this).animate({ backgroundColor: '#C35A33' }, { speed: 1000, queue: false });
            });

            $("#btn_begin").hover(function () {
                    $(this).animate({ backgroundColor: '#30A8F4' }, { speed: 1000, queue: false });
                }, function () {
                    $(this).animate({ backgroundColor: '#C35A33' }, { speed: 1000, queue: false });
            });
            var li_count = parseInt($("#li_count").val(),10);
            if(li_count > 6){
            	$("#content_exam").css("height",$("#content_left").css("height"));
            }else if($("#ui_need").val() == "need"){
            	$("#content_exam").css("height",$("#content_left").css("height"));
            }
        });
    </script>
</head>
<body>
	<%
		HttpSession s = request.getSession();
		Course selectedCourse = (Course)s.getAttribute("selectedCourse");
		String studentName = student.getStuName();
	%>
<div id="bigContent">
<div id="head">
    <div id="title">
        <div class="title_left">
            <div class="titleText">Students Online Exam Platform</div>
        </div>
        <div class="title_right">
            <div class="avatar"><img src="../image/noavatar.jpg" alt="../image/noavatar.jpg"/></div>
            <div class="userState">
                <div class="userState_big"><a href="#"><%=studentName %></a></div>
                <div class="userState_small"><a href="/Exam1/servlet/SLogoutServlet">logout</a></div>
            </div>
        </div>
    </div>
    <form id="navi_form" action="/Exam1/servlet/SNaviSelectServlet">
	    <div id="navi">
	        <div class="navi_top">
	            <ul class="all_navi">
	            	<li id="navi1" class="each_navi navi1">Examination</li>
	                <li id="navi2" class="each_navi navi2">Practice Test </li>
	                <li id="navi3" class="each_navi navi3">Free Q&A</li>
	            </ul>
	        </div>
	        <div class="navi_bottom">
	            <ul class="all_terms">
	            	<li class="each_term term1">freshman 1</li>
	                <li class="each_term term2">freshman 2</li>
	                <li class="each_term term3">sophomore 1</li>
	                <li class="each_term term4">sophomore 2</li>
	                <li class="each_term term5">junior 1</li>
	                <li class="each_term term6">junior 2</li>
	            </ul>
	        </div>
	    </div>
       	<input type="hidden" value="" name="test_type" id="test_type"/>
        <input type="hidden" value="" name="which_term" id="which_term"/>
    </form>
</div>
<div id="content_exam"  class="boxShadow">
    <div id="choose_logo">
        <div class="choose_logo_text">Choose Your Subject And Begin Exam</div>
        <div class="choose_logo_img"></div>
    </div>
    <div id="content_left">
        <div id="courses">
            <div id="courses_title">Courses</div>
            <form id="course_form" action="/Exam1/servlet/SCourseSelectServlet" method="post">
	            <div id="courses_details">
	                <ul id="courses_list">
					<%
						ArrayList<Course> courseList = term.getCourseList();
						Iterator<Course> courseIt = courseList.iterator();
						int courseNum = 0;
						while(courseIt.hasNext()){
							courseNum++;
							Course course = (Course)courseIt.next();
							String courseName = course.getCourseName();
							String courseId = course.getCourseId();
					%>
	                	<li class="<%="li"+courseNum%>" id="<%=courseId%>"><div class="each_course_text"><%=courseName %></div></li>
	                <%} %>	
	                </ul>
	             	<input type="hidden" id="li_count" value="<%=courseNum%>"/>
	            </div>
	            <input type="hidden" value="" id="select_course" name="select_course"/>
	            <input type="hidden" value="" id="select_course_name" name="select_course_name"/>
	            <input type="hidden" value="exam" id="test_type" name="test_type"/>
            </form>
        </div>
    </div>
    <div id="content_right">
    	<%if(selectedCourse!=null){
			String courseName = selectedCourse.getCourseName();
    		if(selectedCourse.getExamPaper()!=null){
    			Paper examPaper = selectedCourse.getExamPaper();
    			String examPaperName = examPaper.getPaperName();
    			SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    			if(examPaper.getTimeStat() == Paper.ISTESTING){    			
    				int examPaperId = examPaper.getPaperId();
    	%>
        <div id="subjects_name"><%=courseName %></div>
        <div id="exam_content">
            <div id="exam_details">
                <div id="exam_name" class="exam_name"><%=examPaperName %></div>
                <div id="exam_notice" class="exam_notice"><p class="exam_notice_title">Notice:</p><div id="exam_notice_text" class="exam_notice_text">Yet my mind seemed to be in quest of something else -- 
                some way that I could personally apply to the close of Thanksgiving. 
                It must have taken me a half hour to sense that maybe some key to an answer could result 
                from reversing the word "Thanksgiving" -- at least that suggested a verbal direction, "Giving thanks."</div></div>
                <form action="/Exam1/servlet/GeneratePaperServlet" method="get">
	                <div id="begin_exam" class="begin_exam">
	                    <input type="submit" id="btn_begin" value="Let's Begin" class="btn_begin1"/>
	                    <input type="hidden" id="paper_id" name="paper_id" value="<%=examPaperId%>"/>
	                </div>
                </form>
            </div>
        </div>
        <%}else if(examPaper.getTimeStat() == Paper.NOTBEGIN){ 
        	String beginTime = df.format(examPaper.getStartTime());
        	//String beginTime = examPaper.getStartTime().toString();
        %>
        <div id="subjects_name"><%=courseName %></div>
        <div id="exam_content">
            <div id="exam_details">
                <div id="exam_name" class="exam_name"><%=examPaperName %></div>
                <div id="exam_notice" class="exam_notice"><p class="exam_notice_title">Notice:</p>
	                <div id="exam_notice_text" class="exam_notice_text">
	                The exam has Not begun,the begin time of the examination is <%=beginTime %>, Please Note.
	                </div>
                </div>
                <div id="begin_exam" class="begin_exam">
                    <input type="submit" id="btn_begin" value="Not Begin"  class="btn_begin2"/>
                    <input type="hidden" id="paper_id" name="paper_id" value=""/>
                </div>
            </div>
        </div>        
        <%}else if(examPaper.getTimeStat() == Paper.FINISHED){ 
        	String endTime = df.format(examPaper.getFinishDate());
        %>
        <div id="subjects_name"><%=courseName %></div>
        <div id="exam_content">
            <div id="exam_details">
                <div id="exam_name" class="exam_name"><%=examPaperName %></div>
                <div id="exam_notice" class="exam_notice"><p class="exam_notice_title">Notice:</p>
	                <div id="exam_notice_text" class="exam_notice_text">
	                The exam has ended, the end time is <%=endTime %>.
	                </div>
                </div>
                <div id="begin_exam" class="begin_exam">
                    <input type="submit" id="btn_begin" value="Ended"  class="btn_begin3"/>
                    <input type="hidden" id="paper_id" name="paper_id" value=""/>
                </div>
            </div>
        </div>       
        <%}}else{ %>
        <div id="subjects_name"><%="No exam papers"%></div>
        <%}}else{ %>
        <div id="subjects_name"><%="Please select a course first"%></div>
        <input type="hidden" id="ui_need" value="need"></input>
        <%}%>
    </div>
    <div id="content_bottom"></div>   
</div>
</div>
</body>
</html>